package com.example.demo.command;

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author LYF
 * @date 2022/6/25
 */
@ShellComponent
public class BaseCommand {

    static List<Integer> mockList  =new ArrayList<>();

    static {
        for(int i=0;i<3;i++){
            mockList.add(new Random().nextInt(200));
        }
    }

    @ShellMethod("add number")
    public int add(int a,int b){
        return a+b;
    }
    @ShellMethod("update")
    public void update(){
        AtomicInteger i = new AtomicInteger();
        i.set(0);
        mockList.forEach(u->{
            System.out.println("step"+i.get()+":exec successfully code("+u.intValue()+")");
            i.getAndIncrement();
        });
        System.out.println("hello has updated");
    }




}
